<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span {
            display: inline-block;
            width: 80px;
        }
    </style>
</head>
<body>
    <span id="stuName"></span>
    <button id="btn">随机点名</button>
    <script>
        function getRandomName() {
            var randomIdx = Math.floor(Math.random() * arr.length) // [0,1) * arr.length
            nameBox.innerText = arr[randomIdx]
        }
        var nameBox = document.getElementById('stuName')
        var btnBox = document.getElementById('btn')
        var arr = ["刘少宁", "梁永昌", "陈飞鑫", "陈剑龙", "张聪聪", "熊家富", "吕运学","王乾坤", "何高峰", "彭琰", "江亲国", "谢卓新", "梁展航", "林夏祺", "卢进球", "杨海涛", "周子琪", "罗东伟", "陈曼娜", "徐文强", "黄武超", "颜子豪", "李展鸿", "欧飞悦", "陈嘉伟", "王访", "刘靖琛", "邹思明", "邱癸坚", "韦靖", "李志合", "覃珍珍", "王津", "陈彩", "张勇", "张敏芳", "卢宗铭"]
        // var randomIdx = Math.floor(Math.random() * arr.length) // [0,1) * arr.length
        // nameBox.innerText = arr[randomIdx]
        getRandomName()

        // btnBox.onclick = getRandomName() //错误：getRandomName()执行后得到返回值undefined
        btnBox.onclick = getRandomName
        
    </script>
</body>
</html>